package de.pass.ch.graph.edge;

public class CompleteEdge extends Edge {

	private static final long serialVersionUID = -2630647327491181754L;

	private int source;

	private CompleteEdge prev;
	private CompleteEdge next;

	public CompleteEdge(int s, int t, int w, boolean sh, boolean f, boolean b) {
		super(t, w, (byte) 0, f, b);
		source = s;
		setShortcut(sh);
		prev = null;
		next = null;
	}

	public CompleteEdge(int s, int t, int w, byte typ, boolean sh, boolean f,
			boolean b, int shE1, int shE2, int shM, int shOEC) {
		super(t, w, typ, f, b, shE1, shE2, shM, shOEC);
		source = s;
		setShortcut(sh);
		prev = null;
		next = null;
	}

	public void setSource(int s) {
		source = (source & Integer.MIN_VALUE) | (s & Integer.MAX_VALUE);
	}

	public void setShortcut(boolean sh) {
		if (sh) {
			source |= Integer.MIN_VALUE;
		} else {
			source &= Integer.MAX_VALUE;
		}
	}

	public int getSource() {
		return source & Integer.MAX_VALUE;
	}

	public boolean isShortcut() {
		return (source & Integer.MIN_VALUE) != 0;
	}

	@Override
	public String toString() {
		String res = source + " ";
		res += isBackward() ? "<" : " ";
		res += "--";
		res += isForward() ? ">" : " ";
		res += " " + getTarget() + "  (" + getWeight() + ")";
		return res;
	}

	public Edge getEdge() {
		return new Edge(getTarget(), getWeight(), getType(), isForward(),
				isBackward());
	}

	public CompleteEdge getPrevious() {
		return prev;
	}

	public CompleteEdge getNext() {
		return next;
	}

	public void setPrevious(CompleteEdge e) {
		prev = e;
	}

	public void setNext(CompleteEdge e) {
		next = e;
	}

}
